﻿#ifndef pala_Utils_h
#define pala_Utils_h

#include "ConvertUTF.h"
#include "cocos2d.h"
#include "../include/blplateform/Define.h"
#include <string>
#ifdef WIN32
#include "platform/third_party/win32/iconv/iconv.h"
#endif

using namespace std;
USING_NS_CC;

using namespace rapidxml;
int getMax(int ,int);
int getMin(int ,int);

int parseInt(string str);
int HexToDec(const char *s);
int parseInt(const char* str);

float parseNumber(const char* str); 
double parseDouble(const char* str);

string  parseString(float i); 
string parseString(int i); 
string parseString(long i); 
string parseString2(int i);


int getRandom(int start,int end);


time_t getUnixTime(); 
long getTimer();

string getTimeStr(long long time=0);

void  splitStr(vector<string> &gRet, string cStr ,const char* cSplit );    

void parseFilePath(const char * pszIn, char * pszOut);

std::string parseFilePath(const char * pszIn);

string readToken(const string & strText, const char * tagStart, const char * tagEnd);


CCPoint  getPosInScreen(CCPoint point,CCNode* pTarget);


CCPoint  getPosInTarget(CCPoint point,CCNode* pTarget);


void  TraceInt(int nNum); 
void  TracePoint(CCPoint pos); 
void Trace(const char * pszFormat, ...);

int readInt(xml_node<> * pItem,const char* cAttr);
float readFloat(xml_node<> * pItem,const char* cAttr); 
void readString(xml_node<> * pItem,const char* cAttr, string & ret);
void readDate(xml_node<> * pItem, const char * pszAttr, tm & pTm);
int readIntArr(xml_node<> * pItem, const char * pszAttr, int * pArr, const char szSplit = ',');	
void readIntArr(xml_node<> * pItem, const char * pszAttr, int ** pArr, int n1, const char szSplit = ';', const char szSubSplit = ',');	 

int utf8ToUnicode(const char * pIn, wchar_t * pOut);
int unicodeToUtf8(const wchar_t * pIn, char * pOut);

int parseMapY(int );

CCPoint parseMapPos(int x,int y);

void parseMapPos(int x,int y,CCPoint& pos);

void interpolate(CCPoint& p1, CCPoint& p2,float param,CCPoint& result);


void replaceStr(string& ,const char* ,const char*);

float getAngle(const CCPoint& p1,const CCPoint& p2);

ccColor3B parseRgb(int hex);

int parseH(const ccColor3B&);

CCRenderTexture* createStroke(CCSprite* label, int size=2, ccColor3B color=ccc3(0,0,0), GLubyte opacity=255);


char* strrevX(char * str); 
char* rtrim(char* str); 
char* ltrim(char* str); 
char* trim(char* str); 
std::string& trimstr(std::string &s); 
std::string& remove_char(std::string& str, char ch); 
std::string&  replace_all_distinct(std::string& str,const std::string& old_value,const std::string& new_value);
template<class T> T parseStringX(const std::string& str);
template<class T> std::string toString(const T& value);   


std::string numToFixedString(uint32 num, int len);
std::string numToMoneyString(uint32 num);
int	moneyStringToNum(std::string str);

string parseTime(int);


#ifdef WIN32
bool IConvConvert(const char *from_charset, const char *to_charset, const char *inbuf, int inlen, char *outbuf, int outlen) ;
#endif

const char* GBKToUTF8(const char* input);
const char* UTF8ToGBK(const char* input);

string getDictValue(const char* key);
string getDictParamValue(const char* key, ...);
int getUtf8Length(const char *str);
char* subUtfString(const char *str, unsigned int start, unsigned int end);

#endif
